package com.ruoyi.web.controller.systembasic;

import java.util.List;

import com.ruoyi.common.core.domain.model.LoginUser;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.ServletUtils;
import com.ruoyi.common.utils.spring.SpringUtils;
import com.ruoyi.framework.web.service.TokenService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.mes.systembasic.domain.SmesWare;
import com.ruoyi.mes.systembasic.service.ISmesWareService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 仓库管理Controller
 * 
 * @author simpsense
 * @date 2020-11-23
 */
@RestController
@RequestMapping("/systembasic/ware")
public class SmesWareController extends BaseController
{
    @Autowired
    private ISmesWareService smesWareService;

    /**
     * 查询仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:list')")
    @GetMapping("/list")
    public TableDataInfo list(SmesWare smesWare)
    {
        startPage();
        List<SmesWare> list = smesWareService.selectSmesWareList(smesWare);
        return getDataTable(list);
    }

    /**
     * 导出仓库管理列表
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:export')")
    @Log(title = "仓库管理", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(SmesWare smesWare)
    {
        List<SmesWare> list = smesWareService.selectSmesWareList(smesWare);
        ExcelUtil<SmesWare> util = new ExcelUtil<SmesWare>(SmesWare.class);
        return util.exportExcel(list, "ware");
    }

    /**
     * 获取仓库管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:query')")
    @GetMapping(value = "/{wareNo}")
    public AjaxResult getInfo(@PathVariable("wareNo") String wareNo)
    {
        return AjaxResult.success(smesWareService.selectSmesWareById(wareNo));
    }

    /**
     * 新增仓库管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:add')")
    @Log(title = "仓库管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SmesWare smesWare)
    {
        smesWare.setCreateUserName(SecurityUtils.getUsername());
        return toAjax(smesWareService.insertSmesWare(smesWare));
    }

    /**
     * 修改仓库管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:edit')")
    @Log(title = "仓库管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SmesWare smesWare)
    {
        smesWare.setUpdateUserName(SecurityUtils.getUsername());
        return toAjax(smesWareService.updateSmesWare(smesWare));
    }

    /**
     * 删除仓库管理
     */
    @PreAuthorize("@ss.hasPermi('systembasic:ware:remove')")
    @Log(title = "仓库管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{wareNos}")
    public AjaxResult remove(@PathVariable String[] wareNos)
    {
        return toAjax(smesWareService.deleteSmesWareByIds(wareNos));
    }
}
